package org.smile.homework01.arthas;

public class Aerocraft {
    private Engine[] engines;
    private int workingEngine = 0;

    public Aerocraft(int engineNumbers) {
        this.engines = new Engine[engineNumbers];
        for (int i = 0; i < engineNumbers; i++) {
            engines[i] = new Engine(i);
            engines[i].describe();
        }
    }

    public void init(int startEngine) {
        this.workingEngine = startEngine;
    }

    public void start() {
        System.out.println("开始运行：");
        while (true) {
            for (int i = 0; i < engines.length; i++) {
                Engine engine = engines[i];
                if (engine.isAvailable(workingEngine)) {
                    engine.working();
                    workingEngine = engine.next() % engines.length;
                } else {
                    engine.prepare();
                }
            }
        }
    }
}
